package com.sgb.goods.widget.pop;

import android.content.Context;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.goods.R;
import com.sgb.goods.entity.CommonStAttrEntity;
import com.sgb.goods.widget.MaxHeightRecyclerView;
import com.sgb.goods.widget.pop.adapter.StAttributeViewAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

/**
 * 描述：商砼属性弹窗
 *
 * @author qiangHeNooo
 * <p>
 * 时间：2021.12.09
 */
public class StAttributeViewWindows extends BasePopWindow<CommonStAttrEntity> {

    private StAttributeViewAdapter stAttributeViewAdapter;

    public StAttributeViewWindows(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.goods_item_attribute_view;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        MaxHeightRecyclerView recyclerView = holder.getPop().findViewById(R.id.goods_recycler_view);
        TextView okView = holder.getPop().findViewById(R.id.attr_goods_confirm);
        TextView resetView = holder.getPop().findViewById(R.id.attr_goods_cancel);
        okView.setOnClickListener(v -> {
            if (!stAttributeViewAdapter.getOtherAttrData().containsKey("strength")) {
                MToast.showToast(mContext, "请选择强度等级");
                return;
            }
            if (!stAttributeViewAdapter.getAdmixtureAttrData().containsKey("admixture") || stAttributeViewAdapter.getAdmixtureAttrData().get("admixture").size() == 0) {
                MToast.showToast(mContext, "请选择外加剂");
                return;
            }
            if (!stAttributeViewAdapter.getOtherAttrData().containsKey("config")) {
                MToast.showToast(mContext, "请选择配置");
                return;
            }
            if (!stAttributeViewAdapter.getOtherAttrData().containsKey("deliveryMethod")) {
                MToast.showToast(mContext, "请选择服务");
                return;
            }
            dissMiss();
            if (onResultClick != null) {
                onResultClick.result(stAttributeViewAdapter.getAdmixtureAttrData(), stAttributeViewAdapter.getOtherAttrData(), null);
            }
        });
        resetView.setOnClickListener(v -> dismiss());
        stAttributeViewAdapter = new StAttributeViewAdapter(mContext, null);
        stAttributeViewAdapter.setMultiSelect(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(stAttributeViewAdapter);
    }

    public void setData(List<CommonStAttrEntity> stAttributeViewEntities, boolean isUpdate) {
        if (isUpdate) {
            stAttributeViewAdapter.setDatas(stAttributeViewEntities);
        }

    }
}
